package cn.tedu._01mvcboot01.controller;

import cn.tedu._01mvcboot01.pojo.dto.BMI;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class bmi {
    @GetMapping("/api/v1/bmi")
    @ResponseBody
    public String getBMI(BMI bmi)
    {

        double b = bmi.getHeight();
        double bm = bmi.getWeight();
        double b3 = bm/(b*b);
        if(b3<18.5)
        {return "过轻";}
        if(b3>=18.5&&b3<24.9)
        {return "正常";}
        if(b3>=24.9&&b3<28.9)
        {return "过重";}
        else if(b3>=28.9&&b3<30)
        {return "肥胖";}
        return "0";

    }

    @GetMapping("/bmi2/{height}/{weight}")
    @ResponseBody
    public String getBMI2(@PathVariable Double height,@PathVariable Double weight)
    {
        double b3 = weight/(height*height);
        if(b3<18.5)
        {return "过轻";}
        if(b3>=18.5&&b3<24.9)
        {return "正常";}
        if(b3>=24.9&&b3<28.9)
        {return "过重";}
        else if(b3>=28.9&&b3<30)
        {return "肥胖";}
        return "0";
    }
}
